/* eslint-disable */

import CryptoJS from 'crypto-js';

const AES_KEYS = {
  ENCRY_IV: '2015030120123456',
  ENCRYPT_PWD_KEY: 'abcdnnnnnn123456',
  DECRYPT_KEY: '0123456789123456',
  DECRYPT_IV: '2015030120123456',
};

// 密码解密
export const aesDecrypt = (msg = '') => {
  msg = msg.replace(/\r\n/g, '');
  let key = CryptoJS.enc.Utf8.parse(AES_KEYS.DECRYPT_KEY); //  UATH5@!#2017caln
  let iv = CryptoJS.enc.Utf8.parse(AES_KEYS.DECRYPT_IV);
  let decrypted = CryptoJS.AES.decrypt(msg, key, {
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
    iv: iv,
  });
  let decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
  return decryptedStr;
};

// 密码单独加密
export const aesEncrypt = word => {
  let key = CryptoJS.enc.Utf8.parse(AES_KEYS.ENCRYPT_PWD_KEY);
  let iv = CryptoJS.enc.Utf8.parse(AES_KEYS.ENCRY_IV);
  let encrypted = CryptoJS.AES.encrypt(word, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.toString();
};
